import torch
from flask import Blueprint, jsonify, request

from models.generator import Generator

generate_bp = Blueprint('generate', __name__)
generator = Generator(input_dim=146, output_dim=146)  # 根据你的数据维度设置


@generate_bp.route('/generate', methods=['POST'])
def generate_samples():
    data = request.json['data']  # 接收前端的数据输入
    noise = torch.randn(len(data), 41)  # 使用随机噪声生成伪装流量
    generated_samples = generator(torch.tensor(noise).float())
    return jsonify(generated_samples.tolist())
    generated_samples = generator(torch.tensor(noise).float())
    return jsonify(generated_samples.tolist())
